//unlogin.js
$(function(){
    $('#login').on('click',unlogin.login);
});

$(document).ready(function() {
    //
});

//处理用户登陆与注册的模块
var unlogin = (function(){
    var login = function() {
        var email = $('#email').val();
        var password = $('#password').val();
        $.ajax({
           type : "GET",
           url : '../testAjax/login.php',
           data : {
               username : email,
               password : password
           },
           dataType : 'json',
           success : function(response) {
               if(response.status === 'ok') {
                  // $.cookie('username')
                   alert("ok");
                   storeEmail({
                       email : email
                   });
                   window.location.href="../index.html";
               } else {
                   loginError();
               }
           },
           error : function(XMLHttpRequest, textStatus, errorThrown) {
               alert(this.url);
           }
        });
    }

    var storeEmail = function(object) {
        $.each(object, function(k,v) {
            setCookie(k,v);
        });
    }

    var loginError = function() {
        alert("用户名或密码错误！");
    }

    return {
        login : login
    }
})();